package com.gxsyh.nantie.order.consumer.controller;

import com.gxsyh.nantie.commons.dto.ResponseResult;
import com.gxsyh.nantie.order.consumer.controller.dto.IsPayDto;
import com.gxsyh.nantie.order.provider.TbOrderService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

/**
 * 订单状态更改
 * @email yom535@outlook.com
 * @author: 刘锋嘉(Liu Fengjia)
 * @date: 2020/2/24
 * @time: 15:54
 * @Description:
 */
@RestController
public class UpdateOrderStatusController {
    @Reference(version = "1.0.0")
    TbOrderService tbOrderService;

    @GetMapping(value = "/order/update/status/is/plan")
    public ResponseResult<Void> updateStatusIsPlan(@RequestParam Long orderid){
        int result = tbOrderService.updateOrderIsPlan(orderid);
        if (result>0)
        {
            return new ResponseResult<>(HttpStatus.OK.value(),"更改订单状态到准备中成功",null);
        }
        else
        {
            return new ResponseResult<>(HttpStatus.OK.value(),"更改订单状态失败",null);

        }
    }

    @GetMapping(value = "/order/update/status/is/done")
    public ResponseResult<Void> updateStatusIsDone(@RequestParam Long orderid){
        int result = tbOrderService.updateOrderIsDone(orderid);
        if (result>0)
        {
            return new ResponseResult<>(HttpStatus.OK.value(),"更改订单状态到完成成功",null);
        }
        else
        {
            return new ResponseResult<>(HttpStatus.BAD_REQUEST.value(),"更改订单状态失败",null);

        }
    }

    @PostMapping(value = "/order/update/pay/status/is/done")
    public ResponseResult<Void> isPay(@RequestBody IsPayDto isPayDto){
        int result = tbOrderService.uodateOrderIsPay(isPayDto.getOrderId(), isPayDto.getPayInfo(), isPayDto.getDepartmentId());
        if (result>0)
        {
            return new ResponseResult<>(HttpStatus.OK.value(),"支付成功",null);
        }
        else
        {
            return new ResponseResult<>(HttpStatus.BAD_REQUEST.value(),"支付失败",null);
        }
    }
}
